﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcmyjobs.Web.enprise
{
    public partial class EnterpriseIndex : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Application["webname"] != null)
                {
                    this.Title = string.Format("单位管理中心-首页  {0}", Application["webname"].ToString());
                }
                if (Session["enterprise_bid"] != null && Session["lastlogin"] != null)
                {
                    DataSet ds = new lcmyjobs.BLL.enterprise_releasejob().GetList(" enterprise_bid=" + Session["enterprise_bid"].ToString());
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        Bind(Session["lastlogin"].ToString(), Convert.ToInt32(Session["enterprise_bid"]));
                    }
                    else
                    {
                        Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请先发布职位！", "RegisterPostJobs.html");
                    }


                }
                else
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请先登陆！", "EnterpriseLogin.html");
                }

            }
        }

        private void Bind(string lastlogin, int enterprise_bid)
        {
            DataSet ds = new lcmyjobs.BLL.enterprise_basic().GetIndexInfo(enterprise_bid);

            lcmyjobs.Model.jobsCount jc = new Model.jobsCount();//记录职位发布信息

            this.lbl_lasttime.Text = lastlogin;//上次登录时间

            if (ds.Tables[0].Rows.Count > 0)
            {
                string memberclass = ds.Tables[0].Rows[0]["memberclass"].ToString();
                //this.lbl_memberclass.Text = memberclass;
                //this.lbl_memberclass1.Text = memberclass;

                if (memberclass != "试用会员")
                {
                    //this.lbl_validity.Text = "有效期还有&nbsp;<span style='color:#ff6600'>" + ds.Tables[0].Rows[0]["validity"]
                           //+ "</span>&nbsp;天，还可以下载简历&nbsp;<span style='color:#ff6600'>" + ds.Tables[0].Rows[0]["membercount"] + "</span>&nbsp;份";
                    //this.lbl_gaoji.Visible = true;
                    //this.lbl_shiyong.Visible = false;

                    //this.LBL_HUIYUAN.Text = "高级会员";
                }
                else
                {
                    //this.lbl_gaoji.Visible = false;
                    //this.lbl_shiyong.Visible = true;
                }
                /*
                if (memberclass != "试用会员")
                {
                    this.LBL_HUIYUAN.Text = "高级会员";
                }
                 * */

                if (memberclass == "顶级会员")
                {
                    //this.LBL_DIANJI.Visible = false;
                    //this.HyperLink1.Visible = false;
                    //this.LBL_HUIYUAN.Visible = false;
                }


                jc.fristJobCount = Convert.ToInt32(ds.Tables[0].Rows[0]["fristjobcount"]);//记录会员可发布的急聘职位总数
                jc.jobsTotalCount = Convert.ToInt32(ds.Tables[0].Rows[0]["releasejobcount"]);

                //this.lbl_jobcount.Text = jc.jobsTotalCount.ToString();//共可发布的职位数


            }

            if (ds.Tables[1].Rows.Count > 0)
            {
                this.lbl_logincount.Text = ds.Tables[1].Rows[0]["logincount"].ToString();//登录次数
                this.lbl_title.Text = ds.Tables[1].Rows[0]["name"].ToString();//单位名

                if (Convert.ToBoolean(ds.Tables[1].Rows[0]["isemp"]))
                {
                    this.lbl_isemp.Text = "招聘中；";
                    this.lbl_isemptxt1.Text = "点击";
                    this.lbl_isemptxt.Visible = true;
                    this.lbn_refresh.Visible = true;
                    this.lbn_setyesisemp.Visible = false;
                    //this.lbn_setnoisemp.Visible = true;
                }
                else
                {
                    this.lbl_isemp.Text = "暂停,";
                    this.lbl_isemptxt1.Text = "使恢复招聘，点击 ";
                    this.lbn_setyesisemp.Visible = true;
                    this.lbn_refresh.Visible = false;
                    //this.lbn_setnoisemp.Visible = false;
                }

                if (Convert.ToBoolean(ds.Tables[1].Rows[0]["ispub"]))
                {
                    //this.lbl_ispubtxt.Text = "公开；";
                    //this.lbl_ispubtxt1.Text = "不允许浏览，点击";
                    //this.lbn_ispubtrue.Visible = false;
                    //this.lbn_ispubfalse.Visible = true;
                }
                else
                {
                    //this.lbl_ispubtxt.Text = "隐藏；";
                    //this.lbl_ispubtxt1.Text = "允许浏览，点击";
                    //this.lbn_ispubtrue.Visible = true;
                    //this.lbn_ispubfalse.Visible = false;
                }
            }

            if (ds.Tables[2].Rows.Count > 0)
            {
                //if ((Convert.ToInt32(this.lbl_jobcount.Text) - Convert.ToInt32(ds.Tables[2].Rows[0]["isUseJobsCount"])) > 0)
                {
                    //this.lbl_jobslast.Text = "" + (Convert.ToInt32(this.lbl_jobcount.Text) - Convert.ToInt32(ds.Tables[2].Rows[0]["isUseJobsCount"]));//还可发布职位数
                }
                //else
                {
                    //this.lbl_jobslast.Text = "0";
                }


                jc.isFristJobsCount = Convert.ToInt32(ds.Tables[2].Rows[0]["isFristJobs"]);//记录当前会也级别内已发布的急聘职位总数（在有效期内且已激活）
                jc.jobsPubCount = Convert.ToInt32(ds.Tables[2].Rows[0]["isUseJobsCount"]);//记录当前会员级别内已发布的职位数(在有效期内已激活)

                this.lbl_isUseJobsCount.Text = ds.Tables[9].Rows[0]["isUseJobsCount"].ToString();//正在招聘的职位数（在有效期内已激活，不计算当前会员级别内的所有已发布的职位，以前会员级别时候发布的职位也包括在内）



                if (ds.Tables[3].Rows.Count > 0)
                {
                    this.lbl_isExpiredJobs.Text = ds.Tables[3].Rows[0]["isExpiredJobsCount"].ToString();//过期职位数（不计算当前会员级别内的所有已发布的职位，以前会员级别时候发布的职位也包括在内）
                }
                if (ds.Tables[4].Rows.Count > 0)
                {
                    int bcount = 0;
                    for (int i = 0; i < ds.Tables[4].Rows.Count; i++)
                    {
                        bcount += Convert.ToInt32(ds.Tables[4].Rows[i]["bcount"]);
                    }

                    this.lbl_bcount.Text = bcount.ToString();//共浏览次数
                }

            }

            if (ds.Tables[5].Rows.Count > 0)
            {
                this.lbl_receive.Text = ds.Tables[5].Rows[0]["totalUserscount"].ToString();//应聘简历份数
                this.lbl_newuid.Text = ds.Tables[5].Rows[0]["isbrowsecount"].ToString();//最新简历
            }

            if (ds.Tables[6].Rows.Count > 0)
            {
                this.lbl_rck.Text = ds.Tables[6].Rows[0]["collectionscount"].ToString();//人才库简历份数
                this.lbl_collection.Text = ds.Tables[6].Rows[0]["collectionscount"].ToString();//收藏夹简历份数
            }
            if (ds.Tables[7].Rows.Count > 0)
            {
                this.lbl_interview.Text = ds.Tables[7].Rows[0]["isInterviewCount"].ToString();//已发送面试邀请的数量

            }
            if (ds.Tables[8].Rows.Count > 0)
            {
                this.lbl_iscome.Text = ds.Tables[8].Rows[0]["isComeCount"].ToString();//已面试过的人数
            }

            if (ds.Tables[10].Rows.Count > 0)
            {
                if (ds.Tables[10].Rows[0]["status"].ToString() == "0")
                {
                    // 已申请，未审核
                    //this.lbl_guding.Text = "您已经申请“<a href='SetTop.html' >（首页）VIP固定位置</a>”显示，我猎头网工作人员会及时与您联络！";
                }
                else if (ds.Tables[10].Rows[0]["status"].ToString() == "1")
                {
                    // 审核通过
                    //if (int.Parse(ds.Tables[10].Rows[0]["validity_last"].ToString()) >= 0)
                    //{
                        //this.lbl_guding.Text = "您已经成功申请“<a href='SetTop.html' >（首页）VIP固定位置</a>”显示，有效期还有<span style='color:#ff6600'>&nbsp;" + ds.Tables[10].Rows[0]["validity_last"].ToString() + "&nbsp;</span>天。";
                    //}
                    //else
                    //{
                        //this.lbl_guding.Text = "您已经成功申请“<a href='SetTop.html' >（首页）VIP固定位置</a>”显示，已过期。继续申请，请点击<a href='SetTop.html' >这里</a>。";
                    //}
                    
                }
            }
            else
            {
                //this.lbl_guding.Text = "您可以申请“<a href='SetTop.html' >（首页）VIP固定位置</a>”显示，提高招聘效果！";
            }


            Session["jobsCount"] = jc;//将职位信息记录到会话中

        }

        //公开
        protected void lbn_ispubtrue_Click(object sender, EventArgs e)
        {
            lcmyjobs.Model.enterprise_basic eb = new Model.enterprise_basic();

            eb.ispub = true;

            if (Session["enterprise_bid"] != null)
            {
                int enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);
                eb.enterprise_bid = enterprise_bid;

                if (new lcmyjobs.BLL.enterprise_basic().UpdateIspub(eb))
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "更新联系方式保密状态成功！", "EnterpriseIndex.html");
                }
            }
        }
        //隐藏
        protected void lbn_ispubfalse_Click(object sender, EventArgs e)
        {
            lcmyjobs.Model.enterprise_basic eb = new Model.enterprise_basic();

            eb.ispub = false;

            if (Session["enterprise_bid"] != null)
            {
                int enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);
                eb.enterprise_bid = enterprise_bid;

                if (new lcmyjobs.BLL.enterprise_basic().UpdateIspub(eb))
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "更新联系方式保密状态成功！", "EnterpriseIndex.html");
                }
            }
        }


        //招聘中
        protected void lbn_setyesisemp_Click(object sender, EventArgs e)
        {
            lcmyjobs.Model.enterprise_basic eb = new Model.enterprise_basic();

            eb.isemp = true;

            if (Session["enterprise_bid"] != null)
            {
                int enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);
                eb.enterprise_bid = enterprise_bid;

                if (new lcmyjobs.BLL.enterprise_basic().UpdateIsemp(eb))
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "更新招聘状态成功！", "EnterpriseIndex.html");
                }
            }

        }
        //暂停招聘
        //protected void lbn_setnoisemp_Click(object sender, EventArgs e)
        //{
        //    lcmyjobs.Model.enterprise_basic eb = new Model.enterprise_basic();

        //    eb.isemp = false;

        //    if (Session["enterprise_bid"] != null)
        //    {
        //        int enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);
        //        eb.enterprise_bid = enterprise_bid;

        //        if (new lcmyjobs.BLL.enterprise_basic().UpdateIsemp(eb))
        //        {
        //            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "更新招聘状态成功！", "EnterpriseIndex.html");
        //        }
        //    }
        //}
        //刷新
        protected void lbn_refresh_Click(object sender, EventArgs e)
        {
            lcmyjobs.BLL.enterprise_releasejob er = new BLL.enterprise_releasejob();

            // 得到本企业的所发布的所有职位ID
            int enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);
            string where = "enterprise_bid=" + enterprise_bid + "and (status=1 or status=3) and isuse=1 and DATEDIFF(DAY,releasetime,GETDATE()) <= validity";
            DataSet ds = er.GetList(where);
            if (ds != null && ds.Tables[0].Rows.Count>0)
            {
                where = "";
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    where += ds.Tables[0].Rows[i]["enterprise_rid"].ToString() ;
                    if ((i + 1) < ds.Tables[0].Rows.Count)
                    {
                        where += ",";
                    }
                }
            }
            else{
                where=null;
            }

            if (er.UpdateWhere("reftime", DateTime.Now.ToString(), where))
            {
                Maticsoft.Common.MessageBox.Show(this, "刷新职位成功！");
            }
        }
    }
}